# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=icingaweb2
pkgver=2.11.1
pkgrel=0
pkgdesc="Web Interface for Icinga2"
url="https://icinga.com/docs/icinga-web-2/latest/doc/01-About/"
# x86: php6-pecl-imagick missing
arch="noarch !armhf !armv7 !s390x !x86"
license="GPL-2.0"
_php=php8
depends="$_php $_php-ldap $_php-intl $_php-dom
	$_php-opcache $_php-session $_php-curl
	$_php-gettext $_php-ctype $_php-openssl $_php-sockets
	$_php-pdo_mysql $_php-pgsql $_php-pdo_pgsql
	$_php-sqlite3 $_php-pdo_sqlite
	icinga-php-library icinga-php-thirdparty"
pkgusers="icingaweb2"
pkggroups="icingaweb2"
options="!check"
install="$pkgname.pre-install $pkgname.post-install"
subpackages="$pkgname-doc $pkgname-bash-completion:bashcomp:noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/Icinga/$pkgname/archive/v$pkgver.tar.gz
fix-env-php8.patch"

# secfixes:
#   2.9.0-r0:
#     - CVE-2021-32746
#     - CVE-2021-32747

build() {
	return 0
}

package() {
	mkdir -p "$pkgdir/etc/$pkgname"
	mkdir -p "$pkgdir/usr/bin"
	mkdir -p "$pkgdir/usr/share/webapps/$pkgname"
	mkdir -p "$pkgdir/var/log/$pkgname"
	mkdir -p "$pkgdir/usr/share/doc/$pkgname"
	cp -r application doc library modules public bin etc "$pkgdir"/usr/share/webapps/$pkgname
	ln -s /usr/share/webapps/icingaweb2/bin/icingacli "$pkgdir"/usr/bin/icingacli
	chmod 2770 "$pkgdir"/etc/$pkgname
	chgrp -R $pkggroups "$pkgdir"/etc/$pkgname
	chmod 750 "$pkgdir"/var/log/$pkgname

	install -d -g $pkggroups -m 0775 "$pkgdir"/var/lib/$pkgname
	install -Dm644 COPYING "$pkgdir/usr/share/licenses/icingaweb2/LICENSE"

	cat >"$pkgdir"/usr/share/doc/$pkgname/README.alpine <<EOF
You need to add to $pkgroups group the owner of the user of your webserver

For nginx, as example:
    # adduser nginx $pkgusers
or
    #adduser nobody $pkgusers

For Apache:
    # adduser apache $pkgusers

For lighttpd:
    # adduser lighttpd $pkgusers

Also, you may remove the user of your webserver from group 'icingacmd' if no other icinga web interface is installed.
EOF
}

bashcomp() {
	depends="bash"
	pkgdesc="Bash completions for $pkgname"

	cd "$builddir"
	mkdir -p "$subpkgdir"/usr/share/bash-completion/completions
	mv etc/bash_completion.d/icingacli "$subpkgdir"/usr/share/bash-completion/completions/icingacli
}

sha512sums="
3df41958de29e6099acfbf002b9cf68da535cfd5400397e03d3ea59083ee68b8084c1cea85ae31cb6134cef2a2b39c18b53cabcbdf436e7ddc14f0ddbcd61997  icingaweb2-2.11.1.tar.gz
bd41f372647566704f847211b05e79a423e6d598251b3d0aa1badb38e389a7c8f1a794419f02b2b4be383354e4154102b1459407d9687c3792f1a2c052589c7d  fix-env-php8.patch
"
